package com.keyinong.jiashiyuan.adapter;

import java.util.ArrayList;

import com.keyinong.jiashiyuan.R;
import com.keyinong.jiashiyuan.entity.XiangqingEntity;
import com.keyinong.jiashiyuan.tools.HttpTools;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class XiangqingAdapter extends BaseAdapter{
	Context context;
	ArrayList<XiangqingEntity> list;
	String id;
	HttpTools httpTools=null;
	
	public XiangqingAdapter(Context context, ArrayList<XiangqingEntity> list ,String id) {
		super();
		this.context = context;
		this.list = list;
		this.id = id;
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return list.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return list.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public View getView(int position, View view, ViewGroup parent) {
		final ViewHandle handle;
		if(view==null){
			handle=new ViewHandle();
			view=LayoutInflater.from(context).inflate(R.layout.item_shangpin, null);
			handle.tv_pinming=(TextView)view.findViewById(R.id.tv_pinming);
			handle.tv_amount=(TextView)view.findViewById(R.id.tv_amount);
			handle.tv_unit=(TextView)view.findViewById(R.id.tv_unit);
			handle.tv_price=(TextView)view.findViewById(R.id.tv_price);
			view.setTag(handle);
		}else {
			handle = (ViewHandle) view.getTag();
		}
		handle.tv_pinming.setText(list.get(position).getName());
		handle.tv_amount.setText("*"+list.get(position).getAmount());
		handle.tv_unit.setText(list.get(position).getUnit());
		handle.tv_price.setText(""+Double.parseDouble(list.get(position).getPrice())*Integer.parseInt(list.get(position).getAmount()));
		return view;
	}
	
	class ViewHandle {
		/**物品名*/
		TextView tv_pinming;
		/**数量*/
		TextView tv_amount;
		/**单位*/
		TextView tv_unit;
		/**价格*/
		TextView tv_price;
	}
	
}
